import { PrismaClient, Prisma } from "@prisma/client";
import { DefaultArgs } from "@prisma/client/runtime/binary";

export class PlatformServe {
    private prisma: PrismaClient;
    private platform: Prisma.PlatformDelegate<DefaultArgs>;

    constructor(prisma: PrismaClient) {
        this.prisma = prisma;
        this.platform = this.prisma.platform;
        this.testConnection();
    }

    private async testConnection() {
        try {
            await this.prisma.$connect();  // 尝试连接数据库
            console.log("Prisma Client 初始化成功，连接数据库成功。");
        } catch (error) {
            console.error("Prisma Client 初始化失败，连接数据库失败：", error);
        }
    }

    async add() {
        try {
            await this.prisma.platform.create({
                data: {
                    name: "百家号111",
                    desc: "最大的软文平台",
                    avatar: "333",
                    url: "3333",
                },
            });
            console.log("平台添加成功");
        } catch (error) {
            console.error("添加平台失败", error);
        }
    }

    async remove() {
        console.log("我要删除了");
    }
}
